﻿using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Media;

namespace Gmantis.Controls
{
    public class ProgressBarTemplateSettings : INotifyPropertyChanged
    {
        // Fields
        private ProgressBar _progressBar;

        // Events
        public event PropertyChangedEventHandler PropertyChanged;

        // Methods
        internal ProgressBarTemplateSettings(ProgressBar progressBar)
        {
            SizeChangedEventHandler handler = null;
            RoutedPropertyChangedEventHandler<double> handler2 = null;
            this._progressBar = progressBar;
            if (handler == null)
            {
                handler = delegate(object s, SizeChangedEventArgs e)
                {
                    this.RaisePropertyChanged("EllipseDiameter");
                    this.RaisePropertyChanged("EllipseOffset");
                    this.RaisePropertyChanged("ContainerAnimationStartPosition");
                    this.RaisePropertyChanged("ContainerAnimationEndPosition");
                    this.RaisePropertyChanged("EllipseAnimationWellPosition");
                    this.RaisePropertyChanged("EllipseAnimationEndPosition");
                    this.RaisePropertyChanged("IndicatorLengthDelta");
                    this.RaisePropertyChanged("IndicatorWidth");
                    RectangleGeometry geometry = new RectangleGeometry
                    {
                        Rect = new Rect(0.0, 0.0, this._progressBar.ActualWidth, this._progressBar.ActualHeight)
                    };
                    this._progressBar.Clip = geometry;
                };
            }
            this._progressBar.SizeChanged += handler;
            if (handler2 == null)
            {
                handler2 = (s, e) => this.RaisePropertyChanged("IndicatorWidth");
            }
            this._progressBar.ValueChanged += handler2;
        }

        private void RaisePropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        // Properties
        public double ContainerAnimationEndPosition
        {
            get
            {
                return ((this._progressBar.ActualWidth / 2.297677) + this.ContainerAnimationStartPosition);
            }
        }

        public double ContainerAnimationStartPosition
        {
            get
            {
                if (this._progressBar.ActualWidth <= 180.0)
                {
                    return -34.0;
                }
                if (this._progressBar.ActualWidth > 280.0)
                {
                    return -63.0;
                }
                return 50.5;
            }
        }

        public double EllipseAnimationEndPosition
        {
            get
            {
                return (this.EllipseAnimationWellPosition * 2.0);
            }
        }

        public double EllipseAnimationWellPosition
        {
            get
            {
                return (this._progressBar.ActualWidth / 3.0);
            }
        }

        public double EllipseDiameter
        {
            get
            {
                if (this._progressBar.ActualWidth <= 180.0)
                {
                    return 4.0;
                }
                if (this._progressBar.ActualWidth > 280.0)
                {
                    return 6.0;
                }
                return 5.0;
            }
        }

        public double EllipseOffset
        {
            get
            {
                if (this._progressBar.ActualWidth <= 180.0)
                {
                    return 4.0;
                }
                if (this._progressBar.ActualWidth > 280.0)
                {
                    return 9.0;
                }
                return 7.0;
            }
        }

        public double IndicatorLengthDelta
        {
            get
            {
                return (this._progressBar.ActualWidth * 0.0);
            }
        }

        public double IndicatorWidth
        {
            get
            {
                Thickness padding = this._progressBar.Padding;
                Thickness borderThickness = this._progressBar.BorderThickness;
                return ((Math.Max((double)0.0, (double)((((this._progressBar.ActualWidth - padding.Left) - padding.Right) - borderThickness.Left) - borderThickness.Right)) * (this._progressBar.Value - this._progressBar.Minimum)) / (this._progressBar.Maximum - this._progressBar.Minimum));
            }
        }
    }
}
